Skip to content

Fix missing IELR splits for multi-symbol reductions - #867

Merged
ydah merged 1 commit into
masterfrom
fix/ielr-multi-symbol-lookaheads
Nov 10, 2026
Merged

ydah merged 1 commit into
masterfrom
fix/ielr-multi-symbol-lookaheads

Conversation

@ydah

@ydah ydah commented Nov 10, 2026

Copy link
Copy Markdown
Member

State#item_lookahead_set used only the first predecessor's goto follows for an item one symbol into its rule. Lookaheads from other incoming paths were lost, which could prevent necessary IELR state splitting and make the generated parser reject valid inputs.

For example:

%define lr.type ielr
%%
start: 'a' left 'd' | 'a' right 'e'
     | 'b' left 'e' | 'b' right 'd';
left: 'x' 'y';
right: 'x' 'y';

Previously this produced 15 states with a reduce/reduce conflict and rejected axye and bxyd. It now produces 17 states without conflicts and accepts all four valid inputs, matching Bison 3.8.2.

Union the goto-follow sets from every predecessor, as in Bison's lookahead calculation (https://github.com/akimd/bison/blob/v3.8.2/src/ielr.c#L412-L423). Add regression coverage for predecessor order, shared right-hand sides of one to three symbols, and acceptance by the generated parser.

Correcting the initial lookaheads can also change splitting for existing grammars. The always_contributions fixture now produces 17 states and five S/R conflicts instead of 15 states and four; its R/R count remains one. All 32,767 tested strings over a and b agree between the old parser, the fixed parser, and Bison. Update the fixture's state/conflict expectations accordingly. State minimality is not addressed here.

@ydah
ydah merged commit c05d49e into master Nov 10, 2026
45 checks passed
@ydah
ydah deleted the fix/ielr-multi-symbol-lookaheads branch November 10, 2026 15:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant